#include <iostream>
using namespace std;

int n;
int jiaWin = 0,jiaLose = 0;
int jia[3],yi[3];

signed main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		char j,y;
		cin>>j>>y;
		if(j=='B'&&y=='C'){
			jia[0]++;
			jiaWin++;
		}
		else if(j=='B'&&y=='J'){
			jiaLose++;
			yi[2]++;
		}
		else if(j=='C'&&y=='B'){
			jiaLose++;
			yi[0]++;
		}
		else if(j=='C'&&y=='J'){
			jiaWin++;
			jia[1]++;
		}
		else if(j=='J'&&y=='B'){
			jiaWin++;
			jia[2]++;
		}
		else if(j=='J'&&y=='C'){
			jiaLose++;
			yi[1]++;
		}
	}
	cout<<jiaWin<<" "<<n-jiaWin-jiaLose<<" "<<jiaLose<<endl;
	cout<<jiaLose<<" "<<n-jiaWin-jiaLose<<" "<<jiaWin<<endl;
	if(jia[0]>=jia[1]){
		if(jia[0]>=jia[2])cout<<"B ";
		else cout<<"J ";
	}
	else{
		if(jia[1]>=jia[2])cout<<"C ";
		else cout<<"J ";
	}
	if(yi[0]>=yi[1]){
		if(yi[0]>=yi[2])cout<<"B ";
		else cout<<"J ";
	}
	else{
		if(yi[1]>=yi[2])cout<<"C ";
		else cout<<"J ";
	}
	return 0;
}
